// 2610. 转换二维数组
// AC: https://leetcode.cn/problems/convert-an-array-into-a-2d-array-with-conditions/submissions/613024263/

class Solution {
public:
    vector<vector<int>> findMatrix(vector<int>& nums) {
        map<int,int> mp;
        for(auto x:nums)
            mp[x]++;
        vector<vector<int>> ans;
        while(!mp.empty()){
            vector<int> res;
            for(auto it = mp.begin();it!= mp.end();){
                it->second-=1;
                res.emplace_back(it->first);
                if(it->second==0)
                    it=mp.erase(it);
                else
                    it++;
            }
            ans.emplace_back(res);
        }
        return ans;
    }
};